package org.tio.sitexxx.service.service.qj;

import com.alibaba.fastjson.JSON;
import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.SqlPara;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tio.sitexxx.service.model.main.Commodity;
import org.tio.sitexxx.service.model.main.Consultant;
import org.tio.sitexxx.service.model.main.Knowledge;
import org.tio.sitexxx.service.vo.Const;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class SearchService {
    private static Logger log	= LoggerFactory.getLogger(SearchService.class);
    public static final SearchService me	= new SearchService();
//    final Wardrobe dao	= new Wardrobe().dao();
    public SearchService(){

    }

    /**
     *
     * @param query
     * @return
     */
    public List<Commodity> getCommoditys(Map<String, Object> query){
        List<Commodity> resultList=new ArrayList<>(6);
        String sqlid = "search.getCommoditys";
        String db = Const.Db.TIO_SITE_MAIN;
        Kv cond=Kv.create().set(query);
        SqlPara sqlPara = Db.use(db).getSqlPara(sqlid,cond);
        List<Record> record = Db.use(db).find(sqlPara);
        for(Record record1:record){
            resultList.add(JSON.parseObject(JSON.toJSONString(record1.getColumns()),Commodity.class));

        }
        return resultList;

    }

    /**
     *
     * @param query
     * @return
     */
    public List<Knowledge> getKnowledges(Map<String, Object> query){
        List<Knowledge> resultList=new ArrayList<>(6);
        String sqlid = "search.getKnowledges";
        String db = Const.Db.TIO_SITE_MAIN;
        Kv cond=Kv.create().set(query);
        SqlPara sqlPara = Db.use(db).getSqlPara(sqlid,cond);
        List<Record> record = Db.use(db).find(sqlPara);
        for(Record record1:record){
            resultList.add(JSON.parseObject(JSON.toJSONString(record1.getColumns()),Knowledge.class));

        }
        return resultList;
    }

    /**
     *
     * @param query
     * @return
     */
    public List<Consultant> getConsultants(Map<String, Object> query){
        List<Consultant> resultList=new ArrayList<>(6);
        String sqlid = "search.getConsultants";
        String db = Const.Db.TIO_SITE_MAIN;
        Kv cond=Kv.create().set(query);
        SqlPara sqlPara = Db.use(db).getSqlPara(sqlid,cond);
        List<Record> record = Db.use(db).find(sqlPara);
        for(Record record1:record){
            resultList.add(JSON.parseObject(JSON.toJSONString(record1.getColumns()),Consultant.class));

        }
        return resultList;
    }
}
